<#include '/admin/header.html' >
<style>
  .layui-input, .layui-textarea{
    width:100%;
  }
  .layui-form-item{
    width: 40%;
    display: inline-block;
  }
  .layui-form-select{
    width: 140px;
    display: inline-block;
    margin-right: 10px;
  }
  .layui-form-pane .layui-form-label{
  	margin-left: 12px;
  	margin-right: 10px;
  }
  .layui-select-title input{
    width:100%;
  }
  .layui-form-radio i{
  	font-size: 20px;
  	margin-top: -7px;	
  }
  .layui-form-radio span{
  	margin-top: -7px;
  }
  .layui-form-item{
  	width: 50%;
  }
</style>
<div class="admin-main">
    <!--表单区域  -->
	<form id="dlytype" class="layui-form layui-form-pane" action="" enctype="multipart/form-data" style="padding-top:10px">
		<div class="basic-config">
		  <span style="color: #53606b;font-size: 18px;margin-left: 10px;">基本信息</span><hr>
		 	<div class="layui-form-item"  style="width: 50%;float: left;">
    			<label class="layui-form-label" style="width: 130px;margin: 0 0 0 12px;float: left;">配送方式名称:</label>
    			<div class="layui-input-block" style="width: 300px;float: left;margin: 0 0 0 0;">
      				<input type="text" maxlength="20"  name="name" placeholder="快递名称10个汉字以内" lay-verify="required" autocomplete="off" class="layui-input">
    			</div>
  			</div>
  			
  			<div class="layui-form-item">
    			<label class="layui-form-label" style="width: 150px">选择默认物流公司:</label>
    			<div class="layui-input-block" style="width: 400px">
      				<select id="corp_id" name="corp_id" >
						<option value="0">请选择物流公司</option>
						<#list logiList as logi>
						<option value="${logi.id }">${logi.name }</option>
						</#list>
					</select>
    			</div>
  			</div>
  			
  			<div class="layui-form-item" style="width: 1200px;">
    			<label class="layui-form-label" style="margin-right: 10px;">重量设置:</label>
    			<div class="layui-input-block">
	    			首重重量&nbsp;
	    			<select id="firstunit" name="firstunit" class="input_text" style="width: 25%">
						<option value="500" label="500克">500克</option>
						<option selected="selected" value="1000" label="1公斤">1公斤</option>
						<option value="1200" label="1.2公斤">1.2公斤</option>
						<option value="2000" label="2公斤">2公斤</option>
						<option value="5000" label="5公斤">5公斤</option>
						<option value="10000" label="10公斤">10公斤</option>
						<option value="20000" label="20公斤">20公斤</option>
						<option value="50000" label="50公斤">50公斤</option>
					</select>&nbsp;续重单位&nbsp;
					<select id="continueunit" name="continueunit" class="input_text" style="width: 25%">
						<option value="500" label="500克">500克</option>
						<option selected="selected" value="1000" label="1公斤">1公斤</option>
						<option value="1200" label="1.2公斤">1.2公斤</option>
						<option value="2000" label="2公斤">2公斤</option>
						<option value="5000" label="5公斤">5公斤</option>
						<option value="10000" label="10公斤">10公斤</option>
						<option value="20000" label="20公斤">20公斤</option>
						<option value="50000" label="50公斤">50公斤</option>
					</select>
					&nbsp;是否启动:&nbsp;
      				<input type="radio" name="disabled" value="0"  title="启用" checked="checked">
      				<input type="radio" name="disabled" value="1"  title="关闭">
    			</div>
  			</div>

  			<div class="layui-form-item">
    			<label class="layui-form-label" style="width: 150px">地区费用类型:</label>
    			<div class="layui-input-block">
      				<input type="radio" name="is_same" value="1" lay-filter="is_same" title="统一设置" checked="checked">
      				<input type="radio" name="is_same" value="0" lay-filter="is_same" title="指定配送地区和费用">
    			</div>
  			</div>
		</div>
  		
  		<div class="unifid-config" id="totle_set">
  			<span style="color: #53606b;font-size: 18px;margin-left: 10px;">统一设置</span><hr>
  			<div class="layui-form-item" style="width: 70%">
    			<label class="layui-form-label" style="width: 150px;margin-right: 15px;">地区费用设置</label>
    			<div class="layui-input-block">
      				<#include 'dlyprice.html' >
    			</div>
  			</div>
  		</div>
  		
  		<div class="unifid-config" id="the_area_set" style="display: none">
  			<span style="color: #53606b;font-size: 18px;">指定地区设置</span><hr>
  			<div class="layui-form-item">
  				<input type="hidden" value="1" id="defAreaFee" name="defAreaFee">
    			<label class="layui-form-label">默认费用配置：</label>
    			<div class="layui-input-block">
      				<#include 'dlyprice.html' >
    			</div>
  			</div>
  			
  			<div class="layui-form-item"  style="display:block;">
    			<label class="layui-form-label">支持配送的地区：</label>
    			<div class="layui-input-block deliveryArea">
						<ol style="list-style: decimal outside; width: 600px;"
							id="sele_area">
						</ol>
					<input type="hidden" id="areacount" name="areacount" value="0">
    				<button class="layui-btn layui-btn-small" type="button" id="addCfgBtn" lay-filter="">为指定的地区设置运费</button>
  				</div>
  			</div>
  		</div>
  		
  		<div class="more-infor">
  		<span style="color: #53606b;font-size: 18px;margin-left: 10px;">更多设置</span><hr>
  		  	<div class="layui-form-item" style="width: 55%;float: left;">
    			<label class="layui-form-label">排序</label>
    			<div class="layui-input-block">
      				<input type="text" id="order" size="5" name="ordernum" id="ordernum" maxlength="5" lay-verify=""  autocomplete="off"  class="layui-input" style="position: absolute;margin-left: 25px;" >
    			</div>
  			</div>
  			
  			<div class="layui-form-item" style="width: 90%;">
    			<label class="layui-form-label">详细介绍:</label>
    			<script id="editor" name="detail" type="text/plain" style="height:200px;width: 85%;float: left;"></script>
  			</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<div class="layui-input-block padding-bottom">
      			<a class="layui-btn" href="javascript:void(0)" lay-submit="" lay-filter="saveBtn">立即提交</a>
      			<button type="reset"  class="layui-btn layui-btn-primary">重置</button>
   			</div>
  		</div>
  	</form>
  	<div class="the_area" style="display: none;">
		 <li style="padding: 7px">
			<div class="deliverycity">
				<span class="delCfgBtn" style="float: right;"> 
					<img border="none" title="删除" alt="删除"
					style="width: 16px; height: 16px; background-image: url('${ctx}/shop/admin/images/ImageBundle.gif'); background-repeat: no-repeat; background-position: 0pt -91px; cursor: pointer;"
					src="${ctx}/shop/admin/images/transparent.gif"> 
				</span> 配送地区 
				<input class="combo input_text layui-input" name="" style="width: 300px;display:inline-block"> 
				<input type="hidden"  name="totle_areas" class="totle_areas" >
				<input type="hidden"  name="totle_regions" class="totle_regions" >
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label><input type="hidden" name="has_cod" value="0" /></label>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</div>
			<div class="deliveryexpbox" style="line-height: 30px;">
				<#include 'dlyprice.html' >
			</div>
		</li>
	</div>
	<div id="divdia"></div>
</div>
<script>

</script>
<script type="text/javascript">


//var index = parent.layer.getFrameIndex(window.name);
var index=parent.parent.layer.index;
   
	$(function() {
		
		layui.use(['form', 'layedit', 'laydate'], function(){
			var form = layui.form(),
			layer = layui.layer,
		    layedit = layui.layedit,
		    laydate = layui.laydate;
			/* 页面渲染 */
			form.render(); 
			
		    form.on('radio(is_same)', function(data){
		    	  if(data.value==1){
		    		  $("#totle_set")[0].style.display="block";
		    		  $("#the_area_set")[0].style.display="none";
		    	  }else {
		    		  $("#totle_set")[0].style.display="none";
		    		  $("#the_area_set")[0].style.display="block";
					}
		    	});  
		    //监听提交
		    form.on('submit(saveBtn)', function(){
		     	var options = {
						url : "${ctx}/shop/admin/dly-type/save-add.do?",
						type : "POST",
						dataType : "json",
						success : function(result) {
							if(result.result==1){
								$.Loading.success(result.message);
								closeCurrent();			//关闭当前页面
						     	newTab('配送方式','${ctx}/shop/admin/dly-type/list-json.do');  //关闭当前页面后无效
							}else{
								$.Loading.error(result.message);
							}
					 	},
						 error : function(e) {
							 $.Loading.error("出现错误 ，请重试");	
						}
				 	};
		     	
				$("#dlytype").ajaxSubmit(options);
				return false; 
		    });
		   
		});
		
		//富文本
		var ue = UE.getEditor('editor');
		
		Dlytype.init();
		
		$(".checkexp").unbind("click").bind("click", function() {
			var btn = $(this);
			Dlytype.checkExp(btn);
		});

		//切换统一和指定地区设置
		/* $(".area_type").click(function() {
			if ($(this).val() == 1) { //1为统一设置
				Dlytype.area_set($("#totle_set"), $("#the_area_set"), 1);
			} else {
				Dlytype.area_set($("#the_area_set"), $("#totle_set"), 0);
			}
		}); */

		//指定地区—启用默认费用
		$("#defAreaFee").click(function() {
			if ($(this).attr("checked") != null) {
				Dlytype.area_set($("#def_price"), null, 1);
			} else {
				Dlytype.area_set(null, $("#def_price"), 0);
			}
		})
		
		//添加指定地区
		$("#addCfgBtn").click(function() {
			var newArea = $(".the_area li").clone().appendTo($(".deliveryArea ol")).show();

			var areacount = $("#areacount").val();
			$("#areacount").val(Number(areacount) + Number(1));

			newArea.find(".combo").attr("name","areas"+ (Number(areacount) + Number(1)));
			newArea.find(".totle_areas").attr("name","totle_areas"+ (Number(areacount) + Number(1)));
			newArea.find(".totle_regions").attr("name","totle_regions"+ (Number(areacount) + Number(1)));
			
			//点击弹出选择配送地区的dialog
			$(".combo").unbind("click").bind("click",function(){
				var $this = $(this);
				Dlytype.optdlytype($this);
			});
			
			Dlytype.area_set(newArea, null, 1);

			$(".delCfgBtn").unbind("click").bind("click",function() {
				$(this).parents("li").remove();
			});

			$(".deliveryArea .checkexp").unbind("click").bind("click", function() {
				var btn = $(this);
				Dlytype.checkExp(btn);
			});

			newArea.find(".price input").each(function() {
				$(this).attr("name",$(this).attr("numberboxname")+ (Number(areacount) + Number(1)));
			});
			
			
			newArea.find("input[name=expressions]").attr("name","expressions" + (Number(areacount) + Number(1)));
			newArea.find("input[name=useexp]").attr("name","useexp" + (Number(areacount) + Number(1)));


			layui.use(['form', 'layedit', 'laydate'], function(){
				var form = layui.form(),
			    layedit = layui.layedit,
			    laydate = layui.laydate;
			    
			    form.render();
			   
			});
		});
	});
	
	var Dlytype = Dlytype || {}
	Dlytype = {
		init : function() {
			Dlytype.area_set($("#totle_set"),null,1);
		},
		area_set : function(showId, hideId, is_true) {
			if (hideId != null) {
				hideId.hide();
			}
			if (showId != null) {
				showId.show();
			}
		},
		price_set : function(objdiv, showClass, hideClass) {
			objdiv.hide();
			objdiv.siblings(".deliveryexp").show();
		},
		checkExp : function(btn) {
			layer.open({
	    		title : "公式验证",//标题
	            maxmin :false,//右上角可否放大缩小
	            type:2,//弹框的类型
	            shade: [0.3, '#000'],//黑色背景
	            shadeClose:false,//黑色背景是否可以点击关闭
	            content:"${ctx}/shop/admin/dly-type/check-exp.do",//内容的URL
	            area:['500px','300px'],//弹框大小
	            scrollbar: false,//是否允许浏览器出现滚动条
	            btn: ['保存'] //可以无限个按钮
				,yes: function(index, layero){
			    //按钮【按钮一】的回调
					layer.close(index);
			  	}
	          });
		},
		optdlytype : function(obj) {
			checkout_areaids = $(obj).parent().find(".totle_areas").val();
			
			layer.open({
	    		title : "选择地区",//标题
	            maxmin :false,//右上角可否放大缩小
	            type:2,//弹框的类型
	            shade: [0.3, '#000'],//黑色背景
	            shadeClose:false,//黑色背景是否可以点击关闭
	            content:"${ctx}/shop/admin/area/get-regions-list.do?regionid=0",//内容的URL
	            area:['600px','300px'],//弹框大小
	            scrollbar: false//是否允许浏览器出现滚动条
	          });
		}
	}
		
</script>
